import Operator from "./Operator";
import {RC} from "../config/RC";
import User from "../entities/User";


class CreateUserObjectOperator extends Operator {
    public async execute(): Promise<RC> {
        let userName: string = this.args.getProperty("userName");
        if(userName === '' || userName === null || userName === undefined){
            return RC.INVALID_ARGUMENT;
        }
        const Id = this.args.getProperty("generateId");
        const encryptedPassword = this.args.getProperty("encryptedPassword");
        const user = new User(Id, userName, encryptedPassword); // 创建一个User对象
        user.insertNewUser();  // 插入数据库

        this.args.setProperty("UserObj", user);
        return RC.SUCCESS;
    }
}

export default CreateUserObjectOperator;